package cn.chencq.moudle.proxyip.site.impl;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import cn.chencq.moudle.proxyip.entity.ProxyIp;
import cn.chencq.moudle.proxyip.site.ProxyListPageParser;

/**
 * 
 * @ClassName: YunDaiLiProxyListPageParser
 * @Description: 云代理(http://www.ip3366.net/?stype=1&page={page}) 24小时更新一次
 * @author: chaoqun.chen
 * @date: 2019年1月31日 下午3:12:24
 */
@Service("yunDaiLiProxyListPageParser")
public class YunDaiLiProxyListPageParser implements ProxyListPageParser {

	@Override
	public List<ProxyIp> parse(String html) {
		List<ProxyIp> list = new ArrayList<>();
		Document doc = Jsoup.parse(html);
		Elements elements = doc.select("div#list table tbody tr");
		for (Element element : elements) {
			String ip = element.select("td:eq(0)").first().text();
			String port = element.select("td:eq(1)").first().text();
			String isAnonymous = element.select("td:eq(2)").first().text();
			String proxyType = element.select("td:eq(3)").first().text().toLowerCase();
			
			String anoymity = "0";
			if ("高匿".contains(isAnonymous)) {
				anoymity = "2";
			} else if ("普通".contains(isAnonymous)) {
				anoymity = "1";
			} else {
				anoymity = "0";
			}
			list.add(new ProxyIp(ip, port, proxyType, anoymity, "0"));
		}
		return null;
	}

}
